'''
自定义模板过滤器
'''

from django import template

register = template.Library()

@register.filter(name='show_dict_first_key_and_content')
def show_dict_first_key_and_content(value):
    # 你的逻辑
    if isinstance(value, dict) and len(value) > 0:
        first_key = list(value.keys())[0]
        first_value = value[first_key]
        if isinstance(first_value, str):
            value = first_value
    return f"The first key is: {first_key}, The first value is {value}"  # 示例：将字符串转换为大写